<?php


namespace app\common\model;


use think\Model;

class Recharge extends Model
{
    protected $pk = "id";
    // 定义时间戳字段名
    protected $createTime = 'add_time';
    //修改format类型
    protected $dateFormat = "Y-m-d H:i:s";
    protected $type=[
        'order_amount'     =>  'float',
    ];
    public function getPkAttr($value,$data) {
        return $this->pk;
    }
    public function user(){
        return $this->hasOne(Users::class, 'user_id','user_id');
    }
    public function getTypeTextAttr($value,$data) {
        $types = [1=>'支付宝',2=>'微信',3=>'银行卡'];
        return $types[$data['type']];
    }
    public function getStatusTextAttr($value,$data) {
        $types = [-1=>'待支付',1=>'已支付',2=>'已取消'];
        return $types[$data['order_status']];
    }
    public function getPayTimeTextAttr($value,$data) {
        if ($data['pay_time']){
            return date($this->dateFormat,$data['pay_time']);
        }
        return '---';
    }
    public function getCancelTimeTextAttr($value,$data) {
        if ($data['cancel_time']){
            return date($this->dateFormat,$data['cancel_time']);
        }
        return '---';
    }
    public function getTimeAttr($value,$data) {
        return $data['add_time'];
    }
}
